package swimv2gm.client.requests;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import swimv2gm.bl.session.WorkRequestManager;

public class ProcessRequest extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
		WorkRequestManager man;
		try {
			man = (WorkRequestManager)InitialContext.doLookup("WorkRequestManager");
		} catch (NamingException e) {
			response.sendError(500);
			return;
		}
		Long uid = (Long)request.getSession().getAttribute("user");

		if (uid == null) {
			response.sendError(403);
			return;
		}

		long id = Long.parseLong(request.getParameter("id"));
		boolean accepted = Boolean.parseBoolean(request.getParameter("accepted"));
		man.processRequest(id,accepted,uid);

		response.sendRedirect("ShowRequest?rid=" + id);
	}

	protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
		doGet(request,response);
	}

}
